iT邦幫忙

2025 iThome 鐵人賽

DAY 4
0
Cloud Native

我在 CKS 考完只拿 47% 後痛定思痛決定好好準備內容系列 第 4

[Day4] 1-3. Properly set up Ingress with TLS

  • 分享至 

  • xImage
  •  

Ingress

  • Ingress 主要提供 http https 也就是 layer 7 的連線設定
  • 連線時主要路徑是 client -> Ingress-managed load balancer -> Ingress -> Routing rules -> Service
  • Ingress controller 可以有多個選項主要是依據架設的地方,如果在CKS考試的話,一預設會使用 Ingress-Nginx Controller
  • Ingress controller 可同時存在多個,可以用名稱取選用

配置範例說明

以下範例主要是針對多種情境的結合做說明,使用時需要依需求做調整

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tls-example-ingress
  annotations:
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true" # 強制使用 https
spec:
  defaultBackend:  # 設定當沒有符合下面 rule 時 預設會訪問的路徑
    service:
      name: test
      port:
        number: 80
  tls:
  - hosts:
      - https-example.foo.com  # 設定訪問 https-example.foo.com 時 tls的配置
    secretName: testsecret-tls # 參考下方 secrets
  rules:
  - host: https-example.foo.com # 如果沒有寫 host 所有請求進來會自動導向該處
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: service1
            port:
              number: 80
  - host: foo.bar.com # 可以使用多個 host
    http:
      paths:
      - path: /foo # 單個 host 可以有多個 path
        pathType: Prefix
        backend:
          service:
            name: service1
            port:
              number: 4200
      - path: /bar
        pathType: Prefix
        backend:
          service:
            name: service2
            port:
              number: 8080
  - host: "*.foo.com" # 除了完整 host 外也可以使用 *
    http:
      paths:
      - pathType: Prefix
        path: "/foo"
        backend:
          service:
            name: service2
            port:
              number: 80          
---
apiVersion: v1
kind: Secret
metadata:
  name: testsecret-tls
  namespace: default
data:
  tls.crt: base64 encoded cert # cat cert.crt | base64 -w 0 => 使用 -w 0 確保沒有換行
  tls.key: base64 encoded key
type: kubernetes.io/tls                  

上一篇
[Day3] 1-2. Use CIS benchmark to review the security configuration of Kubernetes components
下一篇
[Day5] 1-4. Protect node metadata and endpoints
系列文
我在 CKS 考完只拿 47% 後痛定思痛決定好好準備內容25
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言